#include "aky_program/aky_com_include.h"
uint8_t g_flag_low_bat = 0;



void aky_lbt_adc_init(void)
{
    ADC_InitStructure ADC_initStruct;
    ADC_SEQ_InitStructure ADC_SEQ_initStruct;
    PORT_Init(PORTC, PIN5, PORTC_PIN5_ADC0_CH1, 0); // PC.5  => ADC0.CH1
    GPIO_Init(GPIOC, PIN5, 0, 0, 0, 1);

    ADC_initStruct.clk_src = ADC_CLKSRC_HRC_DIV8;
    ADC_initStruct.samplAvg = ADC_AVG_SAMPLE4;
    ADC_initStruct.EOC_IEn = ADC_SEQ0;
    ADC_initStruct.HalfIEn = 0;
    ADC_Init(ADC0, &ADC_initStruct); // 配置ADC

    ADC_SEQ_initStruct.channels = ADC_CH1;
    ADC_SEQ_initStruct.trig_src = ADC_TRIGGER_SW;
    ADC_SEQ_initStruct.conv_cnt = 4;
    ADC_SEQ_initStruct.samp_tim = ADC_SAMPLE_64CLOCK;
    ADC_SEQ_Init(ADC0, ADC_SEQ0, &ADC_SEQ_initStruct);

    ADC_Open(ADC0);      // 使能ADC
    ADC_Calibrate(ADC0); // 校准ADC

    ADC_Start(ADC0, ADC_SEQ0);
}
static uint32_t read_adc_val;

void ADC0_Handler(void)
{
    uint32_t chn;
    ADC0->IF = (1 << ADC_IF_SEQ0EOC_Pos);
    read_adc_val = ADC_Read(ADC0, ADC_SEQ0, &chn);
    ADC_Start(ADC0, ADC_SEQ0);
}

uint16_t bat_val_table[] = {610, 646, 682, 720, 0xffff}; // (7.2 - 6.1) / (4 - 1) = 0.366 每格
static uint8_t get_baterry_cells(uint16_t bat_val)
{
    uint8_t bat_val_table_size = 0;
    uint8_t res = 0;
    bat_val_table_size = sizeof(bat_val_table) / sizeof(bat_val_table[0]);

    for (uint8_t i = 0; i < bat_val_table_size; i++)
    {
        if (bat_val < bat_val_table[i])
        {
            res += i;
            break;
        }
    }
    return res;
}

e_charge_stat_t g_e_charge_stat = NO_CHARGE;
//获取当前检测到的充电状态
e_charge_stat_t get_cur_charge_stat(void)
{
    return g_e_charge_stat;
}

#define CHARGE_DETECT_FIL_LIMIT (5ul) //充电检测滤波次数

//充电状态检测处理 在中断调用
void charge_stat_detect_pro(void)
{
    static uint16_t fil_cnt = 0;
    static uint16_t fil_cnt1 = 0;
    static uint16_t fil_cnt2 = 0;
    static uint16_t fil_cnt3 = 0;
    static uint8_t last_full_stat = 0;//记住上一次电平
    static uint8_t last_charge_stat = 0;
    static uint16_t const_fil_cnt = 0;//电平稳定状态滤波判断
    
    if (last_full_stat != READ_FULL)
    {
        last_full_stat = READ_FULL;
        const_fil_cnt = 0;
    }

    if (last_charge_stat != READ_CHRG)
    {
        last_charge_stat = READ_CHRG;
        const_fil_cnt = 0;
    }

    const_fil_cnt++;
    if (const_fil_cnt < CHARGE_DETECT_FIL_LIMIT * 2)
    {
        //稳定滤波  一段时间电平稳定后才判断其它状态 否则为一直翻转不稳定 没锂电但usb接入状态
        fil_cnt3++;
        if (fil_cnt3 > CHARGE_DETECT_FIL_LIMIT * 3)
        {
            g_e_charge_stat = NO_BAT_AND_USB_INPUT;
        }
    }
    else if (const_fil_cnt >= CHARGE_DETECT_FIL_LIMIT * 2)
    {
        fil_cnt3 = 0;
        //冗余 给一个最大值 预防溢出  
        const_fil_cnt = CHARGE_DETECT_FIL_LIMIT * 2;
        if (READ_FULL == 1 && READ_CHRG == 1)
        {
            //两个引脚都为高电平则是空闲未充电状态
            fil_cnt++;
            fil_cnt1 = 0;
            fil_cnt2 = 0;
            if (fil_cnt > CHARGE_DETECT_FIL_LIMIT)
            {
                fil_cnt = 0;
                g_e_charge_stat = NO_CHARGE;
            }
        }
        else if (READ_FULL == 0 || READ_CHRG == 0)
        {
            if (READ_FULL == 0 && READ_CHRG == 1)
            {
                //full拉低 charge高电平则充满
                fil_cnt = 0;
                fil_cnt1++;
                fil_cnt2 = 0;
                if (fil_cnt1 > CHARGE_DETECT_FIL_LIMIT)
                {
                    fil_cnt1 = 0;
                    g_e_charge_stat = FULL_BAT;
                }
            }
            else if (READ_FULL == 1 && READ_CHRG == 0)
            {
                //full高电平 charge拉低则正在充电
                fil_cnt = 0;
                fil_cnt1 = 0;
                fil_cnt2++;
                if (fil_cnt2 > CHARGE_DETECT_FIL_LIMIT)
                {
                    fil_cnt2 = 0;
                    g_e_charge_stat = CHARGING;
                }
            }
        }
    }
}
//返回低电压检测adc直接值
uint16_t get_bat_row_val(void) 
{
    return read_adc_val;
}
//根据电阻算得出当前电量值
//return 当前电量值  例如电池电压3.4v 则返回340
uint16_t get_cur_bat_val_by_math(void)
{
    uint16_t res;
    static uint16_t last_temp = 0;
    uint32_t temp = 0;
    static uint16_t cnt = 0;
    uint32_t TemplateValueLong = 0;
    TemplateValueLong = get_bat_row_val();

    TemplateValueLong = (TemplateValueLong * SARADC_REFV * (R4 + R5));
    TemplateValueLong = (TemplateValueLong / (SARADC_FULLRANGE * R5));
    TemplateValueLong += V_OFFSET;

    res = TemplateValueLong;

    return res;
}


uint16_t check_low_bat_buf[CHECK_LIMIT] = {0};
uint16_t check_low_bat_cnt = 0;
uint16_t cur_bat_val = 0;
//检测低电前的必要初始化
void check_low_bat_init(void)
{
    check_low_bat_cnt = 0;
}


//是否触发低电压  不阻塞 可以在开始测量后调用
//low_bat_threshold 低电压的阈值
//return \1 触发低电压
uint8_t check_low_bat_trig(uint16_t low_bat_threshold)
{
    uint8_t res = 0;
    uint8_t i = 0;
    uint32_t sum = 0;
#if (AKY_SWITCH_DEVELOP_BOARD == 1)
    return 0;
#endif
    for (i = 0; i < (CHECK_LIMIT - 1); i++)//将低地址数据往高处移动1
    {
        check_low_bat_buf[(CHECK_LIMIT-1)-i] = check_low_bat_buf[(CHECK_LIMIT-2)-i];
    }

    check_low_bat_buf[0] = get_cur_bat_val_by_math();//最新的数据放到最低地址

    check_low_bat_cnt++;
    if (check_low_bat_cnt >= CHECK_LIMIT)
    {
        check_low_bat_cnt = CHECK_LIMIT;
        for (i =  0; i < (CHECK_LIMIT); i++)//得出相加值
        {
            sum += check_low_bat_buf[i];
        }
        sum /= CHECK_LIMIT;
        cur_bat_val = sum;
        if (sum < low_bat_threshold)
        {
            res = 1;
        }
    }
    return res;
}

//低电压检测 会阻塞一段时间 不要在开始测量后调用
//low_bat_threshold 低电压的阈值
//return 返回1则触发低电压
uint8_t check_low_bat_pro(uint16_t low_bat_threshold)
{
    uint16_t time_out = 0;
    uint16_t fil_cnt = 0;
    uint16_t fil_cnt1 = 0;
    uint8_t res = 0;
#if (AKY_SWITCH_DEVELOP_BOARD == 1)
    return 0;
#endif
    check_low_bat_init();
    while (1)
    {
        time_out++;
        if (time_out > 1000)
        {
            goto low_bat_exit;
        }
        
        if (check_low_bat_trig(low_bat_threshold) == 1)
        {
            fil_cnt++;
            fil_cnt1 = 0;
            if (fil_cnt > 5) //低电压触发
            {
                fil_cnt = 0;
                res = 1;
                goto low_bat_exit;
            }
        }
        else
        {
            fil_cnt = 0;
            fil_cnt1++;
            if (fil_cnt1 > (CHECK_LIMIT * 2))
            {
                fil_cnt1 = 0;
                goto low_bat_exit;
            }
        }
    }

low_bat_exit:
    AKY_ASM_NOP();
    return res;
}




#define ADC_LOOP1_MARK (50ul)                // 【一级滤波的采集数据数量】可选比对数量10~200（推荐50）  数值较大反应越慢
#define ADC_LOOP2_MARK (20ul)                // 【二级滤波的采集数据数量】可选比对数量10~200（推荐10）
uint16_t ADC_DATA_BUFF1[ADC_LOOP1_MARK]; // ADC数值存放
uint16_t ADC_DATA_BUFF2[ADC_LOOP2_MARK]; // ADC数值存放

//----------------------以下是平均值滤波算法函数-----------------------//

uint16_t ADCgetavg1(uint16_t adc)
{ // 【一级ADC滤波】读1次ADC值放入以往数组，去掉最大最小值后取平均值。
    uint16_t maxA, minA;
    uint32_t avg;
    uint8_t jA;
    uint8_t max_index, min_index;
    static uint16_t first_cnt = 0;

    max_index = 0;
    min_index = 0;
    avg = 0; // 初始状态ADC值为0
    maxA = 0;
    minA = 0xffff; // 给出最大最小初始值，防止检查最大最小值时出错
    for (jA = 0; jA < (ADC_LOOP1_MARK - 1); jA++)
    {                                                                                          // 将ADC以往数据寄存器的数据位置向左移1组，以空出[0]位存放新的值
        ADC_DATA_BUFF1[(ADC_LOOP1_MARK - 1) - jA] = ADC_DATA_BUFF1[(ADC_LOOP1_MARK - 2) - jA]; // 寄存器的数据位置向左移1组
    }
    ADC_DATA_BUFF1[0] = adc; //[0]位存放新的ADC值
    for (jA = 0; jA < ADC_LOOP1_MARK; jA++)
    { // 检查寄存器中的最大最小值，存入maxA和minA。
        if (maxA <= ADC_DATA_BUFF1[jA])
        {
            maxA = ADC_DATA_BUFF1[jA];
            max_index = jA;
        }
        if (minA >= ADC_DATA_BUFF1[jA])
        {
            minA = ADC_DATA_BUFF1[jA];
            min_index = jA;
        }
    }
    if (min_index == max_index)//如果相等则整个数组都相等 下标需要错开
    {
        if (min_index < (ADC_LOOP1_MARK - 1))
        {
            min_index = max_index + 1; 
        }
        else
        {
            min_index = max_index - 1; 
        }
    }
    
    first_cnt++;
    if (first_cnt < ADC_LOOP1_MARK) //如果数组未填满 则采用当前采集的最大平均
    {
        for (jA = 0; jA < first_cnt; jA++)
        {
            avg += ADC_DATA_BUFF1[jA]; // 
        }
        minA = avg / first_cnt; //
    }
    else//已经填满则采用去掉最大最小值取平均
    {
        first_cnt = ADC_LOOP1_MARK;
        for (jA = 0; jA < ADC_LOOP1_MARK; jA++)
        { // 除去最大最小值之后相加
            if (jA == max_index || jA == min_index) // 当值不是最大最小值时执行
            {
                continue;
            }
            avg += ADC_DATA_BUFF1[jA]; // 其余的值相加
        }
        minA = avg / (ADC_LOOP1_MARK - 2); // 相加后的值去掉后2位，得到稳定的值
    }
    return minA;                       // 返回平均值
}

//二级滤波
uint16_t ADCgetavg2(uint16_t adc)
{ // 【第二级ADC滤波】读10次一级滤波后的数据，只有10次都相同才返回最终电量数据值
    uint8_t jA;
    uint8_t cou = 0;
    uint8_t err_cou = 0;
    static uint8_t first_get = 0;
    for (jA = 1; jA < (ADC_LOOP2_MARK - 1); jA++)
    {                                                                                          // 将ADC以往数据寄存器的数据位置向左移1组，以空出[1]位存放新的值   （注意[ADC_LOOP2_MARK-1]位用于存放最终返回数值）
        ADC_DATA_BUFF2[(ADC_LOOP2_MARK - 1) - jA] = ADC_DATA_BUFF2[(ADC_LOOP2_MARK - 2) - jA]; //  寄存器的数据位置向左移1组
    }
    ADC_DATA_BUFF2[0] = adc; //[0]位存放新的ADC值
    for (jA = 0; jA <= ADC_LOOP2_MARK - 2; jA++)
    { // 比对从[0]到[ADC_LOOP2_MARK-2]
        if (ADC_DATA_BUFF2[jA] == adc)
        {          // 比对数据是否相同
            cou++; // 每相同一次，计数加1
            if (cou >= ADC_LOOP2_MARK - 2)
            {                                             // 当所有读出的数据都相同
                ADC_DATA_BUFF2[ADC_LOOP2_MARK - 1] = adc; // 将最新数据返回
                if (adc > 0)
                {
                    first_get = 1;
                }
                return adc; // 将最新数据返回
            }
        }
        else
        {            // 当比对数据不同时
            cou = 0; // 计数清0
            err_cou++;
            if (err_cou > 3) // 对比出现大于3组不一致则跳出
            {
                err_cou = 0;
                break;
            }
        }
    }
    if (first_get == 0)//如果从未得出过连续相等则返回当前值
    {
        return adc; //
    }
    else//返回历史连续相等值
    {
        return ADC_DATA_BUFF2[ADC_LOOP2_MARK - 1]; // 当比对数据不同时返回之前未更新的数据
    }
}




s_bat_flush_t g_s_bat_flush = {0};

//电池显示控制
void bat_flush_control(e_bat_control_t e_bat_control)
{
    if (e_bat_control == BAT_STOP)
    {
        g_s_bat_flush.flag_start = 0;
        g_s_bat_flush.flag_not_disp = 0;
        g_s_bat_flush.flag_flash_disp = 0;
        g_s_bat_flush.flag_only_up_once = 0;
    }
    else if (e_bat_control == BAT_START)
    {
        g_s_bat_flush.flag_start = 1;
    }
    else if (e_bat_control == BAT_NOT_DISP)
    {
        g_s_bat_flush.flag_not_disp = 1;
    }
    else if (e_bat_control == BAT_DISP)
    {
        g_s_bat_flush.flag_not_disp = 0;
    }
    else if (e_bat_control == BAT_FLASH_DISP)
    {
        g_s_bat_flush.flag_flash_disp = 1;
    }
}
uint8_t get_bat_percent(uint16_t bat_val)
{
    // 电压范围
    const uint16_t min = LOW_BAT_THRESHOLD;
    const uint16_t max = 800;
    
    if(bat_val < min) return 0;
    if(bat_val > max) return 100;
    
    return (uint8_t)((bat_val - min) * 100UL / (max - min));
}
static uint8_t flag_bat_flush_init_ready = 0;

uint8_t get_bat_flush_init_ready(void)
{
    return flag_bat_flush_init_ready;
}
//电池刷新显示处理   
//在定时器中断调用
void bat_flush_pro(void)
{
    uint16_t u16_temp;
    static uint8_t flag_first_get = 0;
    static uint8_t flag_flash_stat = 0;
    static uint32_t u32_tick_last = 0;
    static uint32_t u32_tick_last2 = 0;
    static uint32_t u32_tick_last3 = 0;
    static uint32_t u32_tick_last4 = 0;
    static uint16_t fil_cnt = 0;
    static uint16_t fil_cnt2 = 0;


#if 00
if (g_u32_tick_cnt - u32_tick_last4 > 1000 / 10)
{
    u32_tick_last4 = g_u32_tick_cnt;

    fil_cnt++;
    if (fil_cnt < 15)
    {
        g_e_charge_stat = CHARGING;
    }

    if (fil_cnt > 15 && fil_cnt < 30)
    {
        g_e_charge_stat = FULL_BAT;
    }
    if (fil_cnt > 30)
    {
        g_e_charge_stat = NO_CHARGE;
    }

    printf("bat_percent = %d cur_bat_val = %d bat_percent_disp = %d\n",g_s_bat_flush.cur_bat_percent,g_s_bat_flush.cur_bat_val,g_s_bat_flush.bat_percent_disp);

}

#endif
    if (g_u32_tick_cnt - u32_tick_last2 > 50 / 10)
    {
        u32_tick_last2 = g_u32_tick_cnt;
		{
			u16_temp = get_cur_bat_val_by_math();

			g_s_bat_flush.cur_bat_val = ADCgetavg2(ADCgetavg1(u16_temp)); // 读出ADC2平均值算法 后的稳定值
            g_s_bat_flush.cur_bat_percent = get_bat_percent(g_s_bat_flush.cur_bat_val);

            // printf("bat_percent = %d cur_bat_val = %d\n",g_s_bat_flush.cur_bat_percent,g_s_bat_flush.cur_bat_val);

			if (flag_first_get == 0)
			{
                fil_cnt2++;
                if (fil_cnt2 >= 3)
                {
                    if (fil_cnt2 >= 10)
                    {
                        flag_first_get = 1;
                    }
                    
                    if (fil_cnt2 == 3 || fil_cnt2 == 10)
                    {
                        flag_bat_flush_init_ready = 1;
                        g_s_bat_flush.bat_percent_last = g_s_bat_flush.cur_bat_percent;
                        printf("bat_bar_set_anim_init = %d",g_s_bat_flush.bat_percent_last);
                        u32_tick_last = g_u32_tick_cnt;
                        g_s_bat_flush.bat_percent_disp = g_s_bat_flush.bat_percent_last;
                        if (g_s_bat_flush.bat_percent_disp == 100)
                        {
                            g_s_bat_flush.bat_percent_disp = 99;
                        }
                        if (g_s_bat_flush.bat_percent_disp == 0)
                        {
                            g_s_bat_flush.bat_percent_disp = 1;
                        }
    
                        bat_bar_set_anim_target_val(g_s_bat_flush.bat_percent_disp,g_s_bat_flush.bat_percent_disp);
                        bar_anim(NULL);
                    }
                }
			}
		}
        if (g_s_bat_flush.bat_percent_last != g_s_bat_flush.cur_bat_percent)
        {
            if (g_s_bat_flush.cur_bat_percent > g_s_bat_flush.bat_percent_last) //向上变化
            {
                if (g_s_bat_flush.flag_only_up_once == 0)//每次唤醒只能向上变化一次  后面只能向下变化
                {
                    g_s_bat_flush.flag_only_up_once = 1;
                    g_s_bat_flush.bat_percent_last = g_s_bat_flush.cur_bat_percent;
                } 
            }
            else
            {
                g_s_bat_flush.bat_percent_last = g_s_bat_flush.cur_bat_percent;
            }
        }
    
        if (g_s_bat_flush.bat_percent_disp != g_s_bat_flush.bat_percent_last)
        {
            if ((g_u32_tick_cnt - u32_tick_last) > 60000 / 10)//间隔一段时间
            {
                u32_tick_last = g_u32_tick_cnt;
                if (g_s_bat_flush.bat_percent_disp > g_s_bat_flush.bat_percent_last)
                {
                    g_s_bat_flush.bat_percent_disp--;
                }
                else if (g_s_bat_flush.bat_percent_disp < g_s_bat_flush.bat_percent_last)
                {
                    g_s_bat_flush.bat_percent_disp++;
                }

            }        
        }
        else
        {                
            u32_tick_last = g_u32_tick_cnt;
        }
    }




    if (get_cur_charge_stat() != NO_CHARGE)
    {
        g_s_bat_flush.flag_bat_flash_disp = 0;
        g_s_bat_flush.flag_only_up_once = 0;
        if (get_cur_charge_stat() == FULL_BAT)
        {
            g_s_bat_flush.bat_cells_charge = 4;
            g_s_bat_flush.bat_percent_disp = 100;
            g_s_bat_flush.flag_full_before = 1;
            show_light(2);
        }
        else
        {
            show_light(1);

            // if ((g_u32_tick_cnt - u32_tick_last3) > 1000 / 10)//间隔一段时间
            // {
            //     // printf("g_u32_tick_cnt = %d u32_tick_last = %d",g_u32_tick_cnt,u32_tick_last);
            //     g_s_bat_flush.bat_cells_last = g_s_bat_flush.bat_percent_disp / 25;
            //     u32_tick_last3 = g_u32_tick_cnt;
            //     g_s_bat_flush.bat_cells_charge++;
            //     if (g_s_bat_flush.bat_cells_charge > 4)
            //     {
            //         if (g_s_bat_flush.bat_cells_last == 4)
            //         {
            //             g_s_bat_flush.bat_cells_charge = 3;
            //         }
            //         else
            //         {
            //             g_s_bat_flush.bat_cells_charge = g_s_bat_flush.bat_cells_last;
            //         }
            //     }
            //     if (g_s_bat_flush.bat_percent_disp == 100)
            //     {
            //         g_s_bat_flush.bat_percent_disp = 99;
            //     }

            // }
            
            if (g_s_bat_flush.flag_full_before == 1)
            {
                if (g_s_bat_flush.bat_percent_disp < 100)
                {
                    g_s_bat_flush.flag_full_before = 0;
                }
            }
            else
            {
                if (g_s_bat_flush.bat_percent_disp == 0)
                {
                    g_s_bat_flush.bat_percent_disp = 1;
                }
                else
                {
                    if (g_s_bat_flush.bat_percent_disp == 100)
                    {
                        g_s_bat_flush.bat_percent_disp = 99;
                    }
                }    
    
            }

        }

        bat_bar_set_anim_target_val(g_s_bat_flush.bat_percent_disp,g_s_bat_flush.bat_percent_disp);
        set_disp_bat_flash(g_s_bat_flush.flag_bat_flash_disp);

        return;
    }
    else
    {
        show_light(0);
        g_s_bat_flush.flag_bat_flash_disp = 1;
        set_disp_bat_flash(g_s_bat_flush.flag_bat_flash_disp);
    }

    if (g_s_bat_flush.flag_not_disp == 0)
    {
        if (g_s_bat_flush.bat_percent_disp == 0)
        {
            g_s_bat_flush.bat_percent_disp = 1;
        }
        else
        {
            if (g_s_bat_flush.flag_full_before == 1)
            {
                if (g_s_bat_flush.bat_percent_disp < 100)
                {
                    g_s_bat_flush.flag_full_before = 0;
                }
            }
            else
            {
                if (g_s_bat_flush.bat_percent_disp == 100)
                {
                    g_s_bat_flush.bat_percent_disp = 99;
                }
    
            }
        }                
        bat_bar_set_anim_target_val(g_s_bat_flush.bat_percent_disp,g_s_bat_flush.bat_percent_disp);

    }

}

void show_light(uint8_t stat)
{
    if (stat == 0)
    {
        //不充电
        GREEN_OFF;
        RED_OFF;
    }
    else if (stat == 1)
    {
        //正在充电
        GREEN_OFF;
        RED_ON;
    }
    else if (stat == 2)
    {
        //充满
        GREEN_ON;
        RED_OFF;
    }

}

void bat_init(void)
{
    CHRG_PIN_INIT;
    FULL_PIN_INIT;
    GREEN_PIN_INIT;
    RED_PIN_INIT;
    GREEN_OFF;
    RED_OFF;

    aky_lbt_adc_init();
    g_flag_low_bat = 0;
}
void bat_test(void)
{
    // static uint16_t time_cnt = 0;
    uint16_t u16_temp;
    // time_cnt++;
    // if (time_cnt > 100 / 10)
    // {
    //     time_cnt = 0;
    //     // printf("bat_val:%d\r\n", get_cur_bat_val_by_math());
    //     // printf("row_val:%d\r\n", get_bat_row_val());
    //     printf("full:%d charg:%d\r\n", READ_FULL,READ_CHRG);
    //     // printf("chrg_stat:%d\r\n", READ_CHRG);

    // }
    printf("ADC_LOOP1_MARK = %ld \r\n", ADC_LOOP1_MARK);

    while (1)
    {
        for (uint16_t i = 0; i < ADC_LOOP1_MARK; i++)
        {
            u16_temp = ADCgetavg1(100 + i);
            printf("u16_temp = %d i= %d\r\n", u16_temp,i);
        }
        break;
        
        // printf("bat_cells:%d\r\n", get_baterry_cells(get_cur_bat_val_by_math()));
        // printf("charge_stat:%d\r\n", get_cur_charge_stat());
        // printf("full_stat:%d\r\n", READ_FULL);
        // printf("chrg_stat:%d\r\n", READ_CHRG);
    }
}
